<template>
  <div class="servegroup">
    <ConTitle :info="info"></ConTitle>
    <el-card class="box-card">
      <el-table :data="safeList" stripe style="width: 100%">
        <el-table-column prop="tag" label="标签" width="150"> </el-table-column>
        <el-table-column prop="id" label="密钥ID" width="200">
        </el-table-column>
        <el-table-column prop="authority" label="访问权限"> </el-table-column>
        <el-table-column prop="online" label="密钥状态"> </el-table-column>
        <el-table-column prop="cTime" label="创建时间">
          <template slot-scope="scope">
            {{ scope.row.cTime | cTimeType }}
          </template>
        </el-table-column>
        <el-table-column prop="uTime" label="更新时间">
          <template slot-scope="scope">
            {{ scope.row.uTime | uTimeType }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              circle
              @click="editFun(scope.row)"
            ></el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              circle
              @click="delFun(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import ConTitle from "@/components/ConTitle.vue";
import moment from "moment";
import { $safeList, $safeDel } from "@/api/index";
export default {
  name: "TestlistView",
  data() {
    return {
      info: {
        path: "安全/",
        text: "API访问密钥",
        msg: "-使用访问密钥向SenseCAPAPI服务发出安全的REST或HTTP请求",
      },
      safeList: [],
    };
  },
  components: {
    ConTitle,
  },
  filters: {
    cTimeType(value) {
      return moment(value).format("LL");
    },
    uTimeType(value) {
      return moment(value).format("LL");
    },
  },
  mounted() {
    this.getListData();
  },

  methods: {
    getListData() {
      $safeList().then((res) => {
        console.log(res);
        this.safeList = res.data.data;
      });
    },
    editFun(row) {
      // 页面跳转并传参
      this.$router.push({ path: "/safe/addsafe", query: row });
    },
    delFun(row) {
      console.log(row);
      this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $safeDel({ id: row.id }).then((res) => {
            if (res.data.msg == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getListData();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.sp1 {
  font-weight: 900;
}
.sp {
  margin-left: 80px;
}
.box-card {
  margin-top: 10px;
}
.text {
  margin-top: 20px;
}
.inputt {
  margin-left: 50px;
  width: 300px;
}
.inputt1 {
  margin-left: 75px;
  width: 300px;
}
.beizhu {
  margin-top: 10px;
}
</style>